package megrez.mail.sender.common;

import java.util.ArrayList;
import java.util.List;

import org.springframework.util.StringUtils;

import lombok.Data;

/**
 * 邮件发送对象
 * 
 * @author Lucky Yang
 * @since 0.0.1
 */
@Data
public class MailSenderBean {
    /** 主题 */
    private String subject;
    /** 收件人 */
    private List<String> mailAddresses = new ArrayList<>();
    /** 是否文本 */
    private boolean textable;
    /** 内容 */
    private String body;

    public MailSenderBean addMailAddress(String mailAddress) {
        if (StringUtils.hasText(mailAddress)) {
            mailAddresses.add(mailAddress);
        }
        return this;
    }

    public void validate() {
        if (mailAddresses == null || mailAddresses.isEmpty()) {
            throw new IllegalArgumentException("Mail address list is empty");
        }
    }
}
